// setTimeout实现setInterval

function mySetInterval(callback, delay) {
  let timer = null;
  const interval = function () {
    callback();
    timer = setTimeout(interval, delay);
  }
  timer = setTimeout(interval, delay);

  return {
    cancel: () => { clearTimeout(timer) }
  }
}

// 示例使用
const myInterval = mySetInterval(() => {
  console.log('模拟 setInterval 执行的函数');
}, 1000);

// 5 秒后取消模拟的 setInterval
setTimeout(() => {
  myInterval.cancel();
}, 5000);